<template>
  <div>
    <van-nav-bar title="不凡乐购" left-text="返回" left-arrow @click-left="onClickLeft" class="navbar" />
    <div class="contentBox">
      <div class="order">
        <router-link to="/cart/address" class="address">
          <div class="item">
            <div class="list">
              <div class="addresslist">
                <div class="box1">
                  <p>{{address.name}}</p>
                  <div class="box2" v-if="address.id==this.id">默认</div>
                </div>
                <div class="info">
                  <p class="phone">{{address.mobile}}</p>
                  <p class="point">{{address.address}}</p>
                </div>
                <div class="box3"></div>
              </div>
            </div>
          </div>
        </router-link>
        <div class="orderbox">
          <div class="item">
            <div>商品合计</div>
            <div>￥{{total}}</div>
          </div>
          <div class="item">
            <div>运费</div>
            <div>免运费</div>
          </div>
          <div class="item">
            <div>优惠券</div>
            <div>暂无</div>
          </div>
        </div>
        <div class="cartlist" v-for="item in buylist" :key="item.goods_id">
          <van-card
            :num="item.number"
            :price="item.retail_price"
            :title="item.goods_name"
            :thumb="item.list_pic_url"
            class="item"
          />
        </div>
        <div class="bottom">
          <div class="left">实付：￥{{total}}</div>
          <div class="right" @click="pay">付款</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { Toast } from "vant";
import { getListAction } from "@/api/home";
import { detailAction } from "@/api/nav";
import {mapState} from 'vuex'
export default {
  data() {
    return {
      data: [],
      address: {},
      list: [],
      id: ""
    };
  },
  
  methods: {
    onClickLeft() {
      this.$router.push("/cart");
    },
    pay() {
      Toast("支付功能尚未开通");
    }
  },
  computed: {
    ...mapState(['buylist']),
    total() {
      return this.buylist.reduce((cur, val) => {
        return cur + val.retail_price * val.number;
      }, 0);
    }
  },
  created() {
    console.log(this,this.buylist);
    getListAction({
      openId: 17516331686
    }).then(res => {
      console.log(res.data);
      this.list = res.data;
      var moren = this.list.find(el => el.is_default == 1);
      this.address = moren;
      this.id = moren.id;
    });
    detailAction({
      id: this.$route.query.id
    }).then(res => {
      // console.log(res.data);
      this.address = res.data;
    });
  }
};
</script>

<style lang="scss" scoped>
.contentBox {
  height: calc(100% - 1.24rem);
  // margin-top: 1.22667rem;
  overflow: auto;
  border-top: 0.01333rem solid transparent;
  .order {
    overflow-x: hidden;
    .address {
      display: inline-block;
      width: 100%;
      background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/address-bg-bd30f2bfeb.png)
        0 0 repeat-x #fff;
      padding: 0.66667rem 0 0.4rem 0;
      margin-bottom: 0.26667rem;
      .item {
        padding: 0 0.26667rem;
        .list {
          .addresslist {
            width: 100%;
            position: relative;
            transition: all 0.3s ease;
            display: flex;
            justify-content: space-between;
            align-items: center;
            .box1 {
              width: 1.33333rem;
              text-align: center;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
              align-self: flex-start;
              .box2 {
                width: 0.8rem;
                height: 0.4rem;
                border: 0.01333rem solid #b4282d;
                text-align: center;
                line-height: 0.4rem;
                color: #b4282d;
                margin: 0.13333rem auto 0 auto;
              }
            }
            .info {
              padding: 0 0.26667rem;
              flex: 1;
              .point {
                padding: 0 0.26667rem;
                flex: 1;
              }
            }
            .box3 {
              width: 0.66667rem;
              height: 0.66667rem;
              margin: 0 0.26667rem;
              background: url(http://yanxuan-static.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/address-right-596d39df1e.png)
                no-repeat;
              background-size: 100% 100%;
            }
          }
        }
      }
    }
    .orderbox {
      padding: 0 0.4rem;
      background: #fff;
      .item {
        padding: 0.4rem 0;
        display: flex;
        justify-content: space-between;
        border-bottom: 1px solid #d9d9d9;
      }
    }
    .cartlist {
      background: #fff;
      // margin-bottom: 1.46667rem;
      margin-top: 0.26667rem;
      .item {
        position: relative;
        width: 8.933333rem;
        margin: 0;
        margin-left: 1.066667rem;
        background-color: #fff;
      }
    }
    .bottom {
      position: fixed;
      bottom: 0;
      height: 1.33333rem;
      width: 100%;
      display: flex;
      // justify-content: space-between;
      background: #fff;
      border: 1px solid #ccc;
      .left {
        flex: 1;
        line-height: 1.33333rem;
        padding-left: 0.26667rem;
        text-align: left;
        color: red;
      }
      .right {
        width: 2.66667rem;
        height: 1.33333rem;
        text-align: center;
        line-height: 1.33333rem;
        font-size: 0.38667rem;
        background: #b4282d;
        color: #fff;
      }
    }
  }
}
</style>